let loadingInstance

export default {
  methods: {
    inputValueTrim(event, form, name) {
      if (!form) {
        return
      }

      const value = event.target.value
      form[name] = value.trim()
    },
    openLoading(msg) {
      if (loadingInstance) {
        loadingInstance.close()
        loadingInstance = undefined
      }

      const message = msg || '正在提交数据......'

      loadingInstance = this.$loading({
        lock: true,
        text: message,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    closeLoading() {
      if (loadingInstance) {
        loadingInstance.close()
        loadingInstance = undefined
      }
    }
  }
}
